package main

import (
	"context"
	"embed"
	"fmt"
	"github.com/wailsapp/wails/v2"
	"github.com/wailsapp/wails/v2/pkg/options"
	"github.com/wailsapp/wails/v2/pkg/options/assetserver"
	"smoot-code/service/api"
	"smoot-code/service/factory"
	"smoot-code/service/types"
)

//go:embed all:frontend/dist
var assets embed.FS

func main() {
	err := types.InitConfig()
	if err != nil {
		return
	}
	// Create an instance of the app structure
	fmt.Printf("data:%+v", types.GetConfig().Data)
	data, err := factory.InitData(types.GetConfig().Data)
	if err != nil {
		return
	}
	templateApi := api.NewTemplateApi(data)
	generateApi := api.NewGenerateApi(data)
	editorApi := api.NewEditor(data)

	err = wails.Run(&options.App{
		Title:  "smoot-code",
		Width:  1024,
		Height: 768,
		AssetServer: &assetserver.Options{
			Assets: assets,
		},
		BackgroundColour: &options.RGBA{R: 255, G: 255, B: 255, A: 1},
		OnShutdown: func(ctx context.Context) {

		},
		OnStartup: func(ctx context.Context) {
		},
		Bind: []interface{}{
			templateApi,
			generateApi,
			editorApi,
		},
	})

	if err != nil {
		println("Error:", err.Error())
	}
}
